package com.xunwulian.web.entity;

import com.xunwulian.base.constant.TransStatus;
import com.xunwulian.base.constant.TransType;
import com.xunwulian.base.entity.TransactionEntity;
import com.xunwulian.base.util.DateStyle;
import com.xunwulian.base.util.DateUtil;
import com.xunwulian.base.util.EnumUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;

import java.lang.reflect.InvocationTargetException;

public class TransactionEntityWrapper extends TransactionEntity {

    private String typeStr;

    private String statusStr;

    private String payTimeStr;

    private String createTimeStr;

    public TransactionEntityWrapper() {
    }

    public TransactionEntityWrapper(TransactionEntity entity) {

        try {
            ConvertUtils.register(new DateConverter(null), java.util.Date.class);

            BeanUtils.copyProperties(this, entity);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        this.typeStr = TransType.UNKNOWN.getDesc();
        TransType transType = EnumUtils.getEnumByType(TransType.class, entity.getType());
        if (transType != null) {
            typeStr = transType.getDesc();
        }

        this.statusStr = TransStatus.UNKNOWN.getDesc();
        TransStatus transStatus = EnumUtils.getEnumByType(TransStatus.class, entity.getStatus());
        if (transStatus != null) {
            statusStr = transStatus.getDesc();
        }

        this.createTimeStr = getCreateTime() == null ? "" : DateUtil.DateToString(getCreateTime(), DateStyle.YYYY_MM_DD_HH_MM_SS);
        this.payTimeStr = getPayTime() == null ? "" : DateUtil.DateToString(getPayTime(), DateStyle.YYYY_MM_DD_HH_MM_SS);


    }

    public String getTypeStr() {
        return typeStr;
    }

    public void setTypeStr(String typeStr) {
        this.typeStr = typeStr;
    }

    public String getStatusStr() {
        return statusStr;
    }

    public void setStatusStr(String statusStr) {
        this.statusStr = statusStr;
    }

    public String getPayTimeStr() {
        return payTimeStr;
    }

    public void setPayTimeStr(String payTimeStr) {
        this.payTimeStr = payTimeStr;
    }

    public String getCreateTimeStr() {
        return createTimeStr;
    }

    public void setCreateTimeStr(String createTimeStr) {
        this.createTimeStr = createTimeStr;
    }
}
